data = tempdat)
newdat <- dat
newdat$miss <-miss
# auxiliary variables regressed on missing data indicators
model <- '
male ~ miss
hispanic ~ miss
atriskgrp ~ miss
behsymp1 ~ miss
lrnprob1 ~ miss
reading1 ~ miss
reading2 ~ miss
reading3 ~ miss
reading9 ~ miss
stanread7 ~ miss
math1 ~ miss
math2 ~ miss
math3 ~ miss
math9 ~ miss
stanmath7 ~ miss
'
fit <- sem(model, newdat, fixed.x = T, missing = "fiml")
standardizedSolution(fit, type = "std.nox")
atriskgrp.miss <- miss
set.seed(1234)
tempdat <- dat
# tempdat[,3] <- max(dat[,3]) + 1 - (dat[,3])
reg.miss <- missingness.model.function(Rsq.miss = .15,
prob.miss = .08,
weights = c(0,0,.33,.33,.34,0,0,0,0,0,0,0,0,0,0),
mu = colMeans(tempdat),
sigma = cov(tempdat))
miss <- indicator.function(slopes = reg.miss,
data = tempdat)
newdat <- dat
newdat$miss <-miss
# auxiliary variables regressed on missing data indicators
# auxiliary variables regressed on missing data indicators
model <- '
male ~ miss
hispanic ~ miss
atriskgrp ~ miss
behsymp1 ~ miss
lrnprob1 ~ miss
reading1 ~ miss
reading2 ~ miss
reading3 ~ miss
reading9 ~ miss
stanread7 ~ miss
math1 ~ miss
math2 ~ miss
math3 ~ miss
math9 ~ miss
stanmath7 ~ miss
'
fit <- sem(model, newdat, fixed.x = T, missing = "fiml")
summary(fit)
standardizedSolution(fit, type = "std.nox")
reading1.miss <- miss
math1.miss <- miss
# table(dat$atriskgrp)
set.seed(23132131)
tempdat <- dat
# tempdat[,3] <- max(dat[,3]) + 1 - (dat[,3])
reg.miss <- missingness.model.function(Rsq.miss = .15,
prob.miss = .07,
weights = c(0,0,.33,.33,.34,0,0,0,0,0,0,0,0,0,0),
mu = colMeans(tempdat),
sigma = cov(tempdat))
miss <- indicator.function(slopes = reg.miss,
data = tempdat)
newdat <- dat
newdat$miss <-miss
# auxiliary variables regressed on missing data indicators
# auxiliary variables regressed on missing data indicators
model <- '
male ~ miss
hispanic ~ miss
atriskgrp ~ miss
behsymp1 ~ miss
lrnprob1 ~ miss
reading1 ~ miss
reading2 ~ miss
reading3 ~ miss
reading9 ~ miss
stanread7 ~ miss
math1 ~ miss
math2 ~ miss
math3 ~ miss
math9 ~ miss
stanmath7 ~ miss
'
fit <- sem(model, newdat, fixed.x = T, missing = "fiml")
summary(fit)
standardizedSolution(fit, type = "std.nox")
reading2.miss <- miss
math2.miss <- miss
# table(dat$atriskgrp)
set.seed(6797294)
tempdat <- dat
# tempdat[,3] <- max(dat[,3]) + 1 - (dat[,3])
reg.miss <- missingness.model.function(Rsq.miss = .15,
prob.miss = .13,
weights = c(0,0,.33,.33,.34,0,0,0,0,0,0,0,0,0,0),
mu = colMeans(tempdat),
sigma = cov(tempdat))
miss <- indicator.function(slopes = reg.miss,
data = tempdat)
newdat <- dat
newdat$miss <-miss
# auxiliary variables regressed on missing data indicators
# auxiliary variables regressed on missing data indicators
model <- '
male ~ miss
hispanic ~ miss
atriskgrp ~ miss
behsymp1 ~ miss
lrnprob1 ~ miss
reading1 ~ miss
reading2 ~ miss
reading3 ~ miss
reading9 ~ miss
stanread7 ~ miss
math1 ~ miss
math2 ~ miss
math3 ~ miss
math9 ~ miss
stanmath7 ~ miss
'
fit <- sem(model, newdat, fixed.x = T, missing = "fiml")
summary(fit)
standardizedSolution(fit, type = "std.nox")
reading3.miss <- miss
math3.miss <- miss
# table(dat$atriskgrp)
set.seed(112423)
tempdat <- dat
# tempdat[,3] <- max(dat[,3]) + 1 - (dat[,3])
reg.miss <- missingness.model.function(Rsq.miss = .15,
prob.miss = .15,
weights = c(0,0,.33,.33,.34,0,0,0,0,0,0,0,0,0,0),
mu = colMeans(tempdat),
sigma = cov(tempdat))
miss <- indicator.function(slopes = reg.miss,
data = tempdat)
newdat <- dat
newdat$miss <-miss
# auxiliary variables regressed on missing data indicators
# auxiliary variables regressed on missing data indicators
model <- '
male ~ miss
hispanic ~ miss
atriskgrp ~ miss
behsymp1 ~ miss
lrnprob1 ~ miss
reading1 ~ miss
reading2 ~ miss
reading3 ~ miss
reading9 ~ miss
stanread7 ~ miss
math1 ~ miss
math2 ~ miss
math3 ~ miss
math9 ~ miss
stanmath7 ~ miss
'
fit <- sem(model, newdat, fixed.x = T, missing = "fiml")
summary(fit)
standardizedSolution(fit, type = "std.nox")
reading9.miss <- miss
math9.miss <- miss
# table(dat$atriskgrp)
set.seed(938539045)
tempdat <- dat
# tempdat[,3] <- max(dat[,3]) + 1 - (dat[,3])
reg.miss <- missingness.model.function(Rsq.miss = .15,
prob.miss = .15,
weights = c(0,0,.33,.33,.34,0,0,0,0,0,0,0,0,0,0),
mu = colMeans(tempdat),
sigma = cov(tempdat))
miss <- indicator.function(slopes = reg.miss,
data = tempdat)
newdat <- dat
newdat$miss <-miss
# auxiliary variables regressed on missing data indicators
# auxiliary variables regressed on missing data indicators
model <- '
male ~ miss
hispanic ~ miss
atriskgrp ~ miss
behsymp1 ~ miss
lrnprob1 ~ miss
reading1 ~ miss
reading2 ~ miss
reading3 ~ miss
reading9 ~ miss
stanread7 ~ miss
math1 ~ miss
math2 ~ miss
math3 ~ miss
math9 ~ miss
stanmath7 ~ miss
'
fit <- sem(model, newdat, fixed.x = T, missing = "fiml")
summary(fit)
standardizedSolution(fit, type = "std.nox")
stanread7.miss <- miss
stanmath7.miss <- miss
id <- seq(1:nrow(dat))
datmis <- cbind(id,dat)
datmis[male.miss == 1, 2] <- 999
datmis[hispanic.miss == 1, 3] <- 999
datmis[atriskgrp.miss == 1, 4] <- 999
datmis[behsymp1.miss == 1, 5] <- 999
datmis[lrnprob1.miss == 1, 6] <- 999
datmis[reading1.miss == 1, 7] <- 999
datmis[reading2.miss == 1, 8] <- 999
datmis[reading3.miss == 1, 9] <- 999
datmis[reading9.miss == 1, 10] <- 999
datmis[stanread7.miss == 1, 11] <- 999
datmis[math1.miss == 1, 12] <- 999
datmis[math2.miss == 1, 13] <- 999
datmis[math3.miss == 1, 14] <- 999
datmis[math9.miss == 1, 15] <- 999
datmis[stanmath7.miss == 1, 16] <- 999
write.fwf2(datmis, format.full = c(4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4), format.round = c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), file = "~/desktop/behaviorachievement.miss.dat")
# table(dat$atriskgrp)
set.seed(112423)
tempdat <- dat
# tempdat[,3] <- max(dat[,3]) + 1 - (dat[,3])
reg.miss <- missingness.model.function(Rsq.miss = .15,
prob.miss = .15,
weights = c(0,0,.33,.33,.34,0,0,0,0,0,0,0,0,0,0),
mu = colMeans(tempdat),
sigma = cov(tempdat))
miss <- indicator.function(slopes = reg.miss,
data = tempdat)
newdat <- dat
newdat$miss <-miss
# auxiliary variables regressed on missing data indicators
# auxiliary variables regressed on missing data indicators
model <- '
male ~ miss
hispanic ~ miss
atriskgrp ~ miss
behsymp1 ~ miss
lrnprob1 ~ miss
reading1 ~ miss
reading2 ~ miss
reading3 ~ miss
reading9 ~ miss
stanread7 ~ miss
math1 ~ miss
math2 ~ miss
math3 ~ miss
math9 ~ miss
stanmath7 ~ miss
'
fit <- sem(model, newdat, fixed.x = T, missing = "fiml")
summary(fit)
# example x: analyze moderated regression multiple imputations
# requires fdir and mitml packages
##################################################
# read imputed data
##################################################
# set working directory
fdir::set()
# read imputed data from working directory
imps <- read.table("./imps/imps.dat")
names(imps) <- c("imputation", "id","male","hispanic","atriskgrp","behsymp1","lrnprob1",
"reading1","reading2","reading3","reading9","stanread7","math1","math2","math3","math9","stanmath7")
# center lower-order variables and compute the product
imps$reading1.cgm <- imps$reading1 - mean(imps$reading1)
imps$lrnprob1.cgm <- imps$lrnprob1 - mean(imps$lrnprob1)
imps$reading1.by.lrnprob1 <- imps$reading1.cgm * imps$lrnprob1.cgm
##################################################
# analysis and pooling
##################################################
# sample size and number of predictors
N <- 138
num.predictors <- 5
# analysis and pooling
implist <- mitml::as.mitml.list(split(imps, imps$imputation))
analysis <- with(implist, lm(reading9 ~ reading1.cgm + lrnprob1.cgm + reading1.by.lrnprob1 + male + hispanic))
# significance tests with barnard & rubin degrees of freedom
mitml::testEstimates(analysis, extra.pars = T, df.com = (N-num.predictors-1))
##################################################
# wald and likelihood ratio (omnibus) tests
##################################################
# wald test that all slopes = 0
nullanalysis <- with(implist, lm(reading9 ~ 1))
mitml::testModels(analysis, nullanalysis, df.com = (N-num.predictors-1), method = "D1")
# likelihood ratio test that all slopes = 0
mitml::testModels(analysis, nullanalysis, method = "D3")
##################################################
# test conditional effects (simple slopes)
##################################################
# pooled standard deviation of the moderator
lrnprob1.sd <- mean(unlist(lapply(implist, (function(x) sd(x$lrnprob1.cgm)))))
# test conditional effect (simple slope) at +1 SD above the mean
slope.at.high.lrnprob <- paste0("reading1.cgm + reading1.by.lrnprob1*", 1*lrnprob1.sd)
mitml::testConstraints(analysis, constraints = slope.at.high.lrnprob, df.com = (N-num.predictors-1))
# test conditional effect (simple slope) at the mean
slope.at.mean.lrnprob <- paste0("reading1.cgm + reading1.by.lrnprob1*", 0*lrnprob1.sd)
mitml::testConstraints(analysis, constraints = slope.at.mean.lrnprob, df.com = (N-num.predictors-1))
# test conditional effect (simple slope) at -1 SD below the mean
slope.at.low.lrnprob <- paste0("reading1.cgm + reading1.by.lrnprob1*", -1*lrnprob1.sd)
mitml::testConstraints(analysis, constraints = slope.at.low.lrnprob, df.com = (N-num.predictors-1))
# example x: analyze moderated regression multiple imputations
# requires fdir and mitml packages
##################################################
# read imputed data
##################################################
# set working directory
fdir::set()
# read imputed data from working directory
imps <- read.table("./imps/imps.dat")
names(imps) <- c("imputation", "id","male","hispanic","atriskgrp","behsymp1","lrnprob1",
"reading1","reading2","reading3","reading9","stanread7","math1","math2","math3","math9","stanmath7")
# center lower-order variables and compute the product
imps$reading1.cgm <- imps$reading1 - mean(imps$reading1)
imps$lrnprob1.cgm <- imps$lrnprob1 - mean(imps$lrnprob1)
imps$reading1.by.lrnprob1 <- imps$reading1.cgm * imps$lrnprob1.cgm
##################################################
# analysis and pooling
##################################################
# sample size and number of predictors
N <- 138
num.predictors <- 5
# analysis and pooling
implist <- mitml::as.mitml.list(split(imps, imps$imputation))
analysis <- with(implist, lm(reading9 ~ reading1.cgm + lrnprob1.cgm + reading1.by.lrnprob1 + male + hispanic))
# significance tests with barnard & rubin degrees of freedom
mitml::testEstimates(analysis, extra.pars = T, df.com = (N-num.predictors-1))
##################################################
# wald and likelihood ratio (omnibus) tests
##################################################
# wald test that all slopes = 0
nullanalysis <- with(implist, lm(reading9 ~ 1))
mitml::testModels(analysis, nullanalysis, df.com = (N-num.predictors-1), method = "D1")
# likelihood ratio test that all slopes = 0
mitml::testModels(analysis, nullanalysis, method = "D3")
# example x: analyze moderated regression multiple imputations
# requires fdir and mitml packages
##################################################
# read imputed data
##################################################
# set working directory
fdir::set()
# read imputed data from working directory
imps <- read.table("./imps/imps.dat")
names(imps) <- c("imputation", "id", "male", "frlunch", "achievegrp", "stanread", "efficacy", "anxiety", "mathpre", "mathpost")
# center lower-order variables and compute the squared term
imps$anxiety.cgm <- imps$reading1 - mean(imps$reading1)
# read imputed data from working directory
imps <- read.table("./imps/imps.dat")
names(imps) <- c("imputation", "id", "male", "frlunch", "achievegrp", "stanread", "efficacy", "anxiety", "mathpre", "mathpost")
# center lower-order variables and compute the squared term
imps$anxiety.cgm <- imps$anxiety - mean(imps$anxiety)
imps$anxiety.squared <- imps$anxiety.cgm^2
# sample size and number of predictors
N <- 250
num.predictors <- 4
# analysis and pooling
implist <- mitml::as.mitml.list(split(imps, imps$imputation))
analysis <- with(implist, lm(mathpost ~ anxiety.cgm + anxiety.squared + mathpre + male))
# significance tests with barnard & rubin degrees of freedom
mitml::testEstimates(analysis, extra.pars = T, df.com = (N-num.predictors-1))
# wald test that all slopes = 0
nullanalysis <- with(implist, lm(mathpost ~ 1))
mitml::testModels(analysis, nullanalysis, df.com = (N-num.predictors-1), method = "D1")
# likelihood ratio test that all slopes = 0
mitml::testModels(analysis, nullanalysis, method = "D3")
# example x: analyze linear regression multiple imputations
library(fdir)
library(mdmb)
##################################################
# read imputed data
##################################################
# set working directory
fdir::set()
# read imputed data from working directory
imps <- read.table("./imps/imps.dat")
names(imps) <- c("imputation", "id", "condition", "male", "frlunch", "lowach", "stanread", "efficacy", "anxiety", "mathpre", "mathpost")
# center lower-order variables and compute the squared term
imps$frlunch.cgm <- imps$frlunch - mean(imps$frlunch)
imps$efficacy.cgm <- imps$efficacy - mean(imps$efficacy)
imps$mathpre.cgm <- imps$mathpre - mean(imps$mathpre)
##################################################
# analysis and pooling
##################################################
# sample size and number of predictors
N <- 250
num.predictors <- 4
# analysis and pooling
implist <- as.mitml.list(split(imps, imps$imputation))
# example x: analyze linear regression multiple imputations
library(fdir)
library(mitml)
##################################################
# read imputed data
##################################################
# set working directory
fdir::set()
# read imputed data from working directory
imps <- read.table("./imps/imps.dat")
names(imps) <- c("imputation", "id", "condition", "male", "frlunch", "lowach", "stanread", "efficacy", "anxiety", "mathpre", "mathpost")
# center lower-order variables and compute the squared term
imps$frlunch.cgm <- imps$frlunch - mean(imps$frlunch)
imps$efficacy.cgm <- imps$efficacy - mean(imps$efficacy)
imps$mathpre.cgm <- imps$mathpre - mean(imps$mathpre)
##################################################
# analysis and pooling
##################################################
# sample size and number of predictors
N <- 250
num.predictors <- 4
# analysis and pooling
implist <- as.mitml.list(split(imps, imps$imputation))
analysis <- with(implist, lm(mathpost ~ condition + frlunch.cgm + efficacy.cgm + mathpre.cgm))
# significance tests with barnard & rubin degrees of freedom
estimates <- testEstimates(analysis, extra.pars = T, df.com = (N-num.predictors-1))
estimates
confint(estimates)
##################################################
# wald and likelihood ratio (omnibus) tests
##################################################
# wald test that all slopes = 0
nullanalysis <- with(implist, lm(mathpost ~ 1))
testModels(analysis, nullanalysis, df.com = (N-num.predictors-1), method = "D1")
View(imps)
# example x: analyze linear regression multiple imputations
library(fdir)
library(mitml)
##################################################
# read imputed data
##################################################
# set working directory
fdir::set()
# read imputed data from working directory
imps <- read.table("./imps/imps.dat")
names(imps) <- c("imputation", "id", "condition", "male", "frlunch", "lowach", "stanread", "efficacy", "anxiety", "mathpre", "mathpost")
# center lower-order variables and compute the squared term
imps$frlunch.cgm <- imps$frlunch - mean(imps$frlunch)
imps$efficacy.cgm <- imps$efficacy - mean(imps$efficacy)
imps$mathpre.cgm <- imps$mathpre - mean(imps$mathpre)
##################################################
# analysis and pooling
##################################################
# sample size and number of predictors
N <- 250
num.predictors <- 4
implist <- as.mitml.list(split(imps, imps$imputation))
analysis <- with(implist, lm(mathpost ~ condition + frlunch.cgm + efficacy.cgm + mathpre.cgm))
# significance tests with barnard & rubin degrees of freedom
estimates <- testEstimates(analysis, extra.pars = T, df.com = (N-num.predictors-1))
estimates
confint(estimates)
# example x: analyze linear regression multiple imputations
library(fdir)
library(mitml)
##################################################
# read imputed data
##################################################
# set working directory
set()
# read imputed data from working directory
imps <- read.table("./imps/imps.dat")
names(imps) <- c("imputation", "id", "condition", "male", "frlunch", "atrisk", "stanread", "efficacy", "anxiety", "mathpre", "mathpost")
# center covariates
imps$frlunch.cgm <- imps$frlunch - mean(imps$frlunch)
imps$efficacy.cgm <- imps$efficacy - mean(imps$efficacy)
imps$mathpre.cgm <- imps$mathpre - mean(imps$mathpre)
##################################################
# analysis and pooling
##################################################
# analysis and pooling
implist <- as.mitml.list(split(imps, imps$imputation))
analysis <- with(implist, lm(mathpost ~ condition + frlunch.cgm + efficacy.cgm + mathpre.cgm))
# significance tests with barnard & rubin degrees of freedom
estimates <- testEstimates(analysis, extra.pars = T, df.com = 245)
estimates
confint(estimates)
nullanalysis <- with(implist, lm(mathpost ~ 1))
testModels(analysis, nullanalysis, df.com = 245, method = "D1")
# example x: analyze linear regression multiple imputations
library(fdir)
library(mitml)
##################################################
# read imputed data
##################################################
# set working directory
set()
# read imputed data from working directory
imps <- read.table("./imps/imps.dat")
names(imps) <- c("imputation", "id", "condition", "male", "frlunch", "atrisk", "stanread", "efficacy", "anxiety", "mathpre", "mathpost")
##################################################
# analysis and pooling
##################################################
# analysis and pooling
implist <- as.mitml.list(split(imps, imps$imputation))
fit <- with(implist, lm(mathpost ~ condition + frlunch + efficacy + mathpre))
# significance tests with barnard & rubin degrees of freedom
estimates <- testEstimates(fit, extra.pars = T, df.com = 245)
estimates
confint(estimates)
##################################################
# wald and likelihood ratio (omnibus) tests
##################################################
# wald test that all slopes = 0
null <- with(implist, lm(mathpost ~ 1))
testModels(fit, null, df.com = 245, method = "D1")
